﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;

namespace Frogs.Stability.CircuitBreaker.Behaviors.Actions
{
    class ClosedBehavior : IActionCircuitBehavior
    {
		public void DoAction(Action action)
		{
			try
			{
				action();
				this._executionResult.OnNext(Behaviors.ExecutionResult.Success);
			}
			catch
			{
				this._executionResult.OnNext(Behaviors.ExecutionResult.Fail);
				throw;
			}
		}

        public CircuitState GetStatus()
        {
            return CircuitState.Closed;
        }

		Subject<ExecutionResult> _executionResult = new Subject<ExecutionResult>();
		public IObservable<ExecutionResult> ExecutionResult { get { return this._executionResult; } }
    }
}
